//
//  ViewController.m
//  ComponentLinkDemo
//
//  Created by zhenby on 2017/2/22.
//  Copyright © 2017年 zhenby. All rights reserved.
//

#import "ViewController.h"
#import "ComponentLink.h"
#import "VVViewController.h"
#import "CLComponentXMLParser.h"
#import "AnimationComponent.h"

@interface ViewController ()

@property (nonatomic) id<CLPViewControllerComponent> vcComp;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)gotoChannel:(id)sender {
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"ChannelComponent" ofType:@"xml"];
    id<CLPViewControllerComponent> viewControllerComp = (id<CLPViewControllerComponent>)[CLComponentXMLParser componentWithXMLFile:path];
    
    [self presentViewController:viewControllerComp.compViewController
                       animated:YES
                     completion:NULL];
    
    self.vcComp = viewControllerComp;
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [[self.vcComp subComponents] enumerateObjectsUsingBlock:^(id<CLPComponent>  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if ([obj isKindOfClass:[AnimationComponent class]]) {
                AnimationComponent* ac = (AnimationComponent*)obj;
                CLLayout *layout = [ac.layoutDesc layoutThatFitsInterfaceOrientation:UIInterfaceOrientationPortrait];
                layout.bottom = 0;
                
                [self.vcComp transitionLayoutWithDuration:1.5];
            }
        }];
    });
}

- (IBAction)onActionTest:(id)sender {
    VVViewController* controller = [[VVViewController alloc] init];
    
    [self presentViewController:controller animated:YES completion:^{
        
    }];
}

@end
